<template>
  <div class="ww">
    <el-row class="ee">
      <el-col :span="24">
        <van-nav-bar
          title="商品详情"
          left-text="返回"
          left-arrow
          @click-left="onClickLeft"
        />
      </el-col>
    </el-row>
    <el-row>
      <el-col :span="24">
        <div class="product-image-container">
          <img :src="product.image" alt="product" class="product-image" height="320px">
        </div>
        <div class="product-info-container">
          <span class="product-points">{{ product.score }}积分</span>
          <span class="product-value">价值{{ product.price }}元</span><br>
          <span class="product-name">{{ product.name }}</span><br>
          <span class="product-sold">已兑{{ product.nums }}件</span>
        </div>
      </el-col>
    </el-row>
    <el-row>
      <el-col :span="24">
        <div class="exchange-method-container">
          <span class="exchange-method-title">兑换方法</span>
          <el-steps :active="1" finish-status="success" class="steps">
            <el-step title="选择商品"></el-step>
            <el-step title="填写收货信息"></el-step>
            <el-step title="确认库存状态"></el-step>
            <el-step title="确认收货"></el-step>
          </el-steps>
        </div>
      </el-col>
    </el-row>
    <el-row>
      <el-col :span="24">
        <div class="exchange-condition-container">
          <span class="exchange-condition-title">兑换条件</span>
          <table class="biaoge">
            <tr>
              <td>身份要求:</td>
              <td>仅支持境内手机号码的用户兑换，不支持虚拟兑换。</td>
            </tr>
            <tr>
              <td>兑后须知:</td>
              <td>兑换的商品如无质量问题不支持退换货</td>
            </tr>
            <tr>
              <td>城市/发货:</td>
              <td>港澳台，新疆，海外及疫情地区不发货</td>
            </tr>
            <tr>
              <td>注意事项:</td>
              <td>兑换后不支持修改收货地址。</td>
            </tr>
          </table>
        </div>
      </el-col>
    </el-row>
    <el-row>
      <el-col :span="24">
        <div class="exchange-method-container">
          <span class="exchange-method-title">商品详情</span>
          <div class="exchange-condition-container">
            <p>{{ product.descc }}</p>
          </div>
        </div>
      </el-col>
    </el-row>
    <!-- 新增的固定按钮容器 -->
    <div class="fixed-button-container">
      <div class="button-group">
        <el-button type="primary" size="small" @click="exchange('points')">积分兑换</el-button>
      </div>
    </div>
  </div>
</template>

<script>
import {Toast} from "vant";
import axios from "axios";

export default {
  data() {
    return {
      product: {}
    };
  },
  methods: {
    exchange(type) {
      // 根据type参数处理不同的兑换逻辑
      if (type === 'points') {
        console.log('使用积分兑换');
        this.$router.push({path: '/orderSubmit'})
      } else if (type === 'code') {
        console.log('使用兑换码兑换');
        this.$router.push({path: '/orderSubmit'})
      }
    },
    onClickLeft() {
      Toast('返回');
      //返回上一个页面
      this.$router.push('/show');
    },
  },
  mounted() {
    var goods = localStorage.getItem('goodsXq');
    if (goods) {
      this.product = JSON.parse(goods);
      console.log("product=", goods);
    }
  }
};
</script>

<style scoped>
.ee{
  margin-top: 10px;
}
.ww{
  background-color: #f5f5f5;
}
.biaoge {
  font-size: 13px;
  text-align: left;
  border-collapse: collapse;
  width: 100%;
}

.biaoge td {
  padding: 8px;
  border-bottom: 1px solid #ddd;
}

.biaoge tr:hover {
  background-color: #f5f5f5;
}

.product-header {
  background-color: #FF4D4F;
  color: white;
  padding: 10px;
  text-align: left;
}

.product-image-container {
  text-align: center;
  margin-bottom: 20px;
}

.product-image {
  max-width: 100%;
  border-radius: 8px;
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}

.product-value {
  color: #787676;
  font-size: 14px;
  display: block;
  margin-top: 5px;
}

.product-points {
  color: #e45a5a;
  font-size: 30px;
  display: block;
}

.product-name {
  color: #0c0a0a;
  font-size: 20px;
  font-weight: bold;
  display: block;
  margin-top: 10px;
}

.product-sold {
  color: #787676;
  font-size: 14px;
  display: block;
  margin-top: 5px;
}

.exchange-method-container {
  padding: 20px;
  background-color: #f9f9f9;
  border-radius: 8px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
  margin-bottom: 20px;
}

.steps {
  margin-top: 10px;
}

.exchange-condition-container {
  margin-top: 10px;
}

.fixed-button-container {
  position: fixed;
  bottom: 0;
  left: 0;
  width: 100%;
  background-color: white;
  text-align: center;
  padding: 10px 0;
  box-shadow: 0 -1px 5px rgba(0, 0, 0, 0.1);
  z-index: 1000;
}

.button-group {
  display: inline-block;
  margin: 0 auto;
  text-align: center;
}

.button-group .el-button {
  margin: 0 10px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

@media (max-width: 768px) {
  .product-image {
    height: 240px;
  }

  .product-points {
    font-size: 24px;
  }

  .product-name {
    font-size: 18px;
  }

  .product-value,
  .product-sold {
    font-size: 12px;
  }

  .exchange-method-container,
  .exchange-condition-container {
    padding: 15px;
  }

  .fixed-button-container {
    padding: 8px 0;
  }
}
</style>
